//
//  MBTheComICell.m
//  MiBaoTu
//
//  Created by mac004 on 2016/10/11.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBTheComICell.h"

@implementation MBTheComICell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self= [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatUI];
    }
    return self;
}

-(void)creatUI{
   
    //标题
    self.titleLb=[[UILabel alloc]initWithFrame:CGRectMake(120*PERCEN, 30*PERCEN, 300*PERCEN, 30*PERCEN)];
    self.titleLb.font=[UIFont systemFontOfSize:30*PERCEN];
    self.titleLb.textColor=UIColorFromHex(0x333333);
    [self.contentView addSubview:self.titleLb];
    
    //底图
    UIView * view=[[UIView alloc]initWithFrame:CGRectMake(120*PERCEN, self.titleLb.bottom+20*PERCEN, SCREEN_WIDTH/2048*1808, 540*PERCEN)];
    view.backgroundColor=[UIColorFromHex(0x333333) colorWithAlphaComponent:0.3];
    [self.contentView addSubview:view];
    //大图
    self.bigImageView=[[UIImageView alloc]initWithFrame:CGRectMake(50*PERCEN, 30*PERCEN, view.width-100*PERCEN, view.height/510*420)];
    [view addSubview:self.bigImageView];
    //右上角状态图标
    self.rightImageView=[[UIImageView alloc]initWithFrame:CGRectMake(self.bigImageView.width-160*PERCEN, 0, 160*PERCEN, 160*PERCEN)];
    [self.bigImageView addSubview:self.rightImageView];
    
    //时钟图标
    UIImageView * imgView=[[UIImageView alloc]initWithFrame:CGRectMake(50*PERCEN, view.height-50*PERCEN, 30*PERCEN, 30*PERCEN)];
    imgView.image=[UIImage imageNamed:@"dingshi_sz"];
    [view addSubview:imgView];
    //活动时间
    self.activityLb=[[UILabel  alloc]initWithFrame:CGRectMake(imgView.right+20*PERCEN, imgView.top, 400*PERCEN, 30*PERCEN)];
    self.activityLb.font=[UIFont systemFontOfSize:30*PERCEN];
    self.activityLb.textColor=UIColorFromHex(0x333333);
    [view addSubview:self.activityLb];
    
    //活动人数
    self.numLb=[[UILabel alloc]initWithFrame:CGRectMake(view.width-350*PERCEN, imgView.top, 300*PERCEN, 30*PERCEN)];
    self.numLb.font=[UIFont systemFontOfSize:30*PERCEN];
    self.numLb.textColor=UIColorFromHex(0x333333);
    [view addSubview:self.numLb];
}

- (int)onSolveTimeWithStart:(NSString *)start withEndTimer:(NSString *)end
{
    NSDate *dateStart = [NSDate dateWithTimeIntervalSince1970:[start doubleValue]];
    NSDate *dateEnd = [NSDate dateWithTimeIntervalSince1970:[end doubleValue]];
    NSDate *date = [NSDate date];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"yyyyMMdd"];
    NSString *startStr = [dateFormatter stringFromDate:dateStart];
    NSString *endStr = [dateFormatter stringFromDate:dateEnd];
    NSString *nowStr = [dateFormatter stringFromDate:date];
    
    if ([nowStr intValue] >= [startStr intValue] && [nowStr intValue] <= [endStr intValue]) {
        //进行
        return 1;
    }
    else if ([nowStr intValue] > [endStr intValue]) {
        //结束
        return 2;
    }
    return 0;
}

- (NSString *)onGetTimeWithStart:(NSString *)start withEndTimer:(NSString *)end
{
    NSDate *dateStart = [NSDate dateWithTimeIntervalSince1970:[start doubleValue]];
    NSDate *dateEnd = [NSDate dateWithTimeIntervalSince1970:[end doubleValue]];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"MM.dd"];
    NSString *startStr = [dateFormatter stringFromDate:dateStart];
    NSString *endStr = [dateFormatter stringFromDate:dateEnd];
    
    return [NSString stringWithFormat:@"%@-%@",startStr,endStr];
}
-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic=dataDic;
    self.titleLb.text=_dataDic[@"ActivityName"];
    if (![_dataDic[@"PicPath2"] isKindOfClass:[NSNull class]]) {
        [self.bigImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,_dataDic[@"PicPath2"]]] placeholderImage:[UIImage imageNamed:@"bisai_moren"]];
    }else{
        self.bigImageView.image=[UIImage imageNamed:@"bisai_moren"];
    }
    self.activityLb.text=[NSString stringWithFormat:@"%@ - %@",_dataDic[@"StartTime"],_dataDic[@"EndTime"]];
    
    
    //时间
    NSString *StartTime = [_dataDic objectForKey:@"StartTime"];
    NSString *EndTime = [_dataDic objectForKey:@"EndTime"];
    int isActivity = [self onSolveTimeWithStart:StartTime withEndTimer:EndTime];
    if (isActivity == 1) {
        _rightImageView.image = [UIImage imageNamed:@"jinxingzhong"];
    }
    else if (isActivity == 2) {
        _rightImageView.image = [UIImage imageNamed:@"yijieshu"];
    }
    else {
        //        _rightImageView.image = [UIImage imageNamed:@"yijieshu"];
    }
   _activityLb.text = [NSString stringWithFormat:@"活动时间: %@",[self onGetTimeWithStart:StartTime withEndTimer:EndTime]];
    self.numLb.text=[NSString stringWithFormat:@"参与人数:%@人",_dataDic[@"Nums"]];
}
@end
